package vip.xiaonuo.smzq.modular.lifecycle.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回格式：泛型格式
 *
 * @param <T>
 */
@Data
@NoArgsConstructor
@ApiModel
public class WebResult<T> {

    @ApiModelProperty(value = "状态码")
    Integer code;
    @ApiModelProperty(value = "状态描述")
    String retval;
    @ApiModelProperty(value = "结果数据")
    T data;

    public WebResult(Integer code, String retval) {
        super();
        this.code = code;
        this.retval = retval;
    }

    public WebResult(Integer code, String retval, T data) {
        super();
        this.code = code;
        this.retval = retval;
        this.data = data;
    }

    public Map<String, Object> result() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", this.code);
        map.put("retval", this.retval);
        if (this.data != null) {
            map.put("data", this.data);
        }
        return map;
    }


}
